using Newtonsoft.Json;
using System;

namespace BanZuiCloudControlAgent.Core.Mqtt.Models
{
    /// <summary>
    /// EMQX基础消息模型，所有消息类型的基类
    /// </summary>
    public class BaseMessageModel
    {
        /// <summary>
        /// 消息ID，全局唯一，建议使用UUID
        /// </summary>
        [JsonProperty("messageId")]
        public string MessageId { get; set; }

        /// <summary>
        /// 消息类型，如"STATUS_REPORT"、"TASK_REPORT"等
        /// </summary>
        [JsonProperty("messageType")]
        public string MessageType { get; set; }

        /// <summary>
        /// 消息发送时间戳（毫秒）
        /// </summary>
        [JsonProperty("timestamp")]
        public string Timestamp { get; set; }

        /// <summary>
        /// 设备码，全局唯一标识
        /// </summary>
        [JsonProperty("deviceCode")]
        public string DeviceCode { get; set; }

        /// <summary>
        /// 消息负载，不同消息类型有不同的结构
        /// </summary>
        [JsonProperty("payload")]
        public object Payload { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseMessageModel()
        {
            MessageId = Guid.NewGuid().ToString();
            Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="messageType">消息类型</param>
        /// <param name="deviceCode">设备码</param>
        /// <param name="payload">消息负载</param>
        public BaseMessageModel(string messageType, string deviceCode, object payload)
        {
            MessageId = Guid.NewGuid().ToString();
            MessageType = messageType;
            Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
            DeviceCode = deviceCode;
            Payload = payload;
        }
    }
} 